//
//  MqForumTableViewCell.m
//  Meiqi
//
//  Created by lanou on 16/1/11.
//  Copyright © 2016年 KFC. All rights reserved.
//

#import "MqForumTableViewCell.h"
#import <UIImageView+WebCache.h>
#define kForumChoiceAPI @"http://bbs.biketo.com/api/mobile/index.php?forum=digest&module=new_thread&page=1&version=4"

#define kMartinGap 10
@implementation MqForumTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self addSubviews];
    }
    
    return self;
    
}

//  添加子视图
- (void)addSubviews{
    
    _subjectLabel = [[UILabel alloc] initWithFrame:CGRectMake(kMartinGap, kMartinGap, (kScreenWidth - 2 * kMartinGap) / 5 * 4, 20)];
//    _subjectLabel.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:_subjectLabel];
    
    _msginfosLabel = [[UILabel alloc] initWithFrame:CGRectMake(_subjectLabel.left, _subjectLabel.bottom + kMartinGap, _subjectLabel.width, 60)];
    _msginfosLabel.font = [UIFont systemFontOfSize:13];
    _msginfosLabel.numberOfLines = 0;
    _msginfosLabel.textColor = [UIColor lightGrayColor];
//    _msginfosLabel.backgroundColor = [UIColor blueColor];
    [self.contentView addSubview:_msginfosLabel];
    
    _authorlabel = [[UILabel alloc] initWithFrame:CGRectMake(_msginfosLabel.left, _msginfosLabel.bottom + kMartinGap, _msginfosLabel.width / 2, 15)];
//    _authorlabel.backgroundColor = [UIColor yellowColor];
    [_authorlabel setFont:[UIFont systemFontOfSize:12]];
    _authorlabel.textColor = [UIColor lightGrayColor];

    [self.contentView addSubview:_authorlabel];
    
    _forumnameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_subjectLabel.left + _subjectLabel.width / 2, _authorlabel.top, _msginfosLabel.width / 2, 12)];
//    _forumnameLabel.backgroundColor = [UIColor magentaColor];
    _forumnameLabel.font = [UIFont systemFontOfSize:12];
    _forumnameLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:_forumnameLabel];
    
    _coverImageV = [[UIImageView alloc] initWithFrame:CGRectMake(_msginfosLabel.right + kMartinGap, _msginfosLabel.top, _msginfosLabel.width / 5, _msginfosLabel.height)];
//    _coverImageV.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:_coverImageV];
    
    
}

- (void)setModel:(MqForumModel *)model{
    
    _model = model;
    
    _subjectLabel.text = model.subject;
    _authorlabel.text = model.author;
    _msginfosLabel.text = model.msginfos;
    _forumnameLabel.text = [NSString stringWithFormat:@"【%@】", model.forumname];
    
    //  第三方类库加载图片
    if (model.coverpath != nil) {
        
        NSString *url = [@"http://bbs.biketo.com" stringByAppendingPathComponent:model.coverpath];
        
        [_coverImageV sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:nil];
        
    }
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
